<template>
  <div class="announcements-page">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>公告管理</span>
          <el-button type="primary" @click="handleAdd">发布公告</el-button>
        </div>
      </template>
      <el-table :data="announcements" style="width: 100%">
        <el-table-column prop="title" label="标题" />
        <el-table-column prop="type" label="类型" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <el-tag :type="getStatusType(scope.row.status)">{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="publisher" label="发布人" />
        <el-table-column prop="publishTime" label="发布时间" />
        <el-table-column label="操作" width="250">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button 
              size="small" 
              type="success" 
              v-if="scope.row.status === '草稿'"
              @click="handlePublish(scope.row)"
            >发布</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const announcements = ref([])

const getStatusType = (status) => {
  const statusMap = {
    '草稿': 'info',
    '已发布': 'success',
    '已过期': 'warning'
  }
  return statusMap[status] || 'info'
}

const handleAdd = () => {
  // TODO: 实现发布公告逻辑
}

const handleEdit = (row) => {
  // TODO: 实现编辑公告逻辑
}

const handlePublish = (row) => {
  // TODO: 实现发布公告逻辑
}

const handleDelete = (row) => {
  // TODO: 实现删除公告逻辑
}
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>